//工厂方法模式
#include<iostream>
#include<memory>
using namespace std;

class Fruit{
    public:
    virtual void show(){
        cout<<"这是一个水果"<<endl;
    }
};
class Apple:public Fruit{
    public:
    void show() override{
        cout<<"这是一个苹果"<<endl;
    }
};
class Banana:public Fruit{
    public:
    void show() override{
        cout<<"这是一个香蕉"<<endl;
    }
};

class FruitFactor{
    public:
    virtual shared_ptr<Fruit> create()=0;
};
class AppleFactor:public FruitFactor{
    public:
    shared_ptr<Fruit> create() override{
        return make_shared<Apple>();
    }
};
class BananaFactor:public FruitFactor{
    public:
    shared_ptr<Fruit> create() override{
        return make_shared<Banana>();
    }
};

int main()
{
    shared_ptr<FruitFactor> factor(new AppleFactor());
    shared_ptr<Fruit> fruit=factor->create();
    fruit->show();
    factor.reset(new BananaFactor());
    fruit=factor->create();
    fruit->show();
    return 0;
}